package csc.fresher.spring.annotationuniqueusername;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import org.springframework.beans.factory.annotation.Autowired;

import csc.fresher.spring.dao.UserDAOImpl;
import csc.fresher.spring.model.User;

public class UniqueUsernameValidator implements
		ConstraintValidator<UniqueUsername, String> {

	@Autowired
	private UserDAOImpl dao;

	@Override
	public void initialize(UniqueUsername constraintAnnotation) {
		// TODO Auto-generated method stub

	}

	@Override
	public boolean isValid(String username, ConstraintValidatorContext context) {
		if (dao.checkUser(username)) {
			return false;
		} else {
			return true;
		}
	}

}
